// 混入
// 构造函数类型
// Function
type ClassConstructor = new (...args: any[]) => any;

// 使用泛型
type Constructor<T = {}> = new (...args: any[]) => T;


// 基础类
class MyClass{
  constructor(public name: string){}
}

// 通过闭包实现混入
function Timestamped<TBase extends Constructor>(Base:TBase) {
  return class extends Base{
    timestamp = Date.now();
  }
}

function Printable<TBase extends Constructor>(Base: TBase) {
  return class extends Base{
    print() {
      console.log(this);
    }
  }
}

const TimeAndPrintMyClass = Printable(Timestamped(MyClass));
const example = new TimeAndPrintMyClass("test");
console.log(example.name);
console.log(example.timestamp);
example.print();